﻿// windownative.h
#ifndef WINDOWNATIVE_H
#define WINDOWNATIVE_H

#include <QObject>
#include <QWindow>
#include <QRect>
#include <QPoint>

// Windows 头文件
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <dwmapi.h>
#include <windowsx.h>

// 手动加载 dwmapi.dll 函数（MinGW 可能需要）
typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPtr)(HWND, const MARGINS*);
typedef HRESULT (WINAPI *DwmSetWindowAttributePtr)(HWND, DWORD, LPCVOID, DWORD);

// 兼容性定义
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif

class WindowsNative : public QObject
{
    Q_OBJECT
public:
    explicit WindowsNative(QObject *parent = nullptr);

    Q_INVOKABLE void setWindowFrame(QWindow *window);
    Q_INVOKABLE void setWindowTitleBar(QWindow *window, int titleBarHeight);
    Q_INVOKABLE void startSystemMove(QWindow *window, const QPoint &cursorPos);
    Q_INVOKABLE void startSystemResize(QWindow *window, const QPoint &cursorPos, Qt::Edges edges);
    Q_INVOKABLE void showSystemMenu(QWindow *window, const QPoint &pos);
    Q_INVOKABLE void maximizeWindow(QWindow *window);
    Q_INVOKABLE void minimizeWindow(QWindow *window);
    Q_INVOKABLE void restoreWindow(QWindow *window);
    Q_INVOKABLE void closeWindow(QWindow *window);
    Q_INVOKABLE bool isWindowMaximized(QWindow *window);
    Q_INVOKABLE bool isWindowFullScreen(QWindow *window);

signals:
    void windowStateChanged(int state);

private:
    static QWindow *findWindowHandle(QWindow *window);
};

#endif // WINDOWNATIVE_H
